#include <REGX52.H>
#include "Delay.h"
#include "Nixie.H"
#include "IR.h"
#include "Timer1.h"

sbit Motor=P1^0;

unsigned char Num,Speed;
unsigned char T1Count,Compare=0;
unsigned char Address,Command;

void main()
{
	IR_Init();
	Timer1_Init();
	Nixie(1,Speed);
	while(1)
	{
		if(IR_GetDataFlag()||IR_GetIR_RepeatFlag())
		{
			Address=IR_GetAddress();
			Command=IR_GetCommand();
			if(Command==0x15)
			{
				Speed--;
				Speed%=10;
				if(Speed){Compare=Speed*5+55;}
				else{Compare=Speed;}
			}
			if(Command==0x09)
			{
				Speed++;
				Speed%=10;
				if(Speed){Compare=Speed*5+55;}
				else{Compare=Speed;}
			}
			Nixie(1,Speed);
		}
		
	}
}

void Timer1_Routine() interrupt 3
{
	static unsigned int T1Count;
	TL1 = 0x9C;				
	TH1 = 0xFF;
	T1Count++;
	T1Count%=100;
	if(T1Count<Compare)
	{
		Motor=1;
	}
	else
	{
		Motor=0;
	}	
}
